package com.frxuexi.visit.view

import android.os.Bundle
import android.view.View
import com.google.android.material.snackbar.Snackbar
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.lib_base.mvvm.BaseActivity
import com.frxuexi.visit.R
import com.frxuexi.visit.VisitViewModel
import com.frxuexi.visit.databinding.ActivityVisitDetailBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/visit/VisitDetailActivity")
@AndroidEntryPoint
class VisitDetailActivity : BaseActivity<ActivityVisitDetailBinding,VisitViewModel>() {
    @Autowired
    lateinit var vid:String
    override fun initData() {
        vm.visitsByIdData.observe(this){
            binding.bean=it
            if(it.visitStatus=="待审核"){
                binding.visitdetailGroup.visibility=View.VISIBLE
            }
        }

        vm.approveVisitsData.observe(this){
            ToastUtils.showLong("审批完成")
            finish()
        }
    }

    override fun initView() {
        ARouter.getInstance().inject(this)
        vm.getVisitById(vid.toInt())

        binding.visitdetailBtn.setOnClickListener {
            if(binding.visitdetailRg.checkedRadioButtonId==R.id.visitdetail_yes){
                vm.approveVisit(vid.toInt())
            }else{
                vm.rejectVisit(vid.toInt())
            }
        }
    }

}